package com.peak.distribution.schedule;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.peak.distribution.service.order.DisOrderService;
import com.peak.spring.boot.tools.DatePattern;
import com.peak.spring.boot.tools.Dates;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class OrderSchedule {
	
	@Autowired
	private DisOrderService orderService;

	@Scheduled(cron = "${schedule.auto.close.unpay.order}")
	public void autoCloseUnpayOrder() {
		Date now = Dates.now();
		log.info("清理未支付订单任务启动{}", Dates.format(now, DatePattern.SHORT_LINE_TIME));
		orderService.closeUnpayOrder();
		log.info("清理未支付订单任务结束，用时{}秒", (Dates.now().getTime() - now.getTime()) / 1000);
	}
	
	@Scheduled(cron = "${schedule.alert.delivery.order}")
	public void alertDeliveryOrder() {
		Date now = Dates.now();
		log.info("提醒有代发货订单任务启动{}", Dates.format(now, DatePattern.SHORT_LINE_TIME));
		orderService.alertDeliveryOrder();
		log.info("提醒有代发货订单任务结束，用时{}秒", (Dates.now().getTime() - now.getTime()) / 1000);
	}
	
	@Scheduled(cron = "${schedule.check.receive.order}")
	public void checkReceiveOrder() {
		Date now = Dates.now();
		log.info("检查收货订单任务启动{}", Dates.format(now, DatePattern.SHORT_LINE_TIME));
		orderService.checkReceiveOrder();
		log.info("检查收货订单任务结束，用时{}秒", (Dates.now().getTime() - now.getTime()) / 1000);
	}
}
